﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.IO;


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        delegate DialogResult CallMessageBoxDelegate(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon);
        BackgroundWorker bckIniciarComponetes;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // Create a new instance of the form.
            Form Form2 = new Form();
            // Create two buttons to use as the accept and cancel buttons.
            Button button1 = new Button();
            Button button2 = new Button();

            // Set the text of button1 to "OK".
            button1.Text = "OK";
            // Set the position of the button on the form.
            button1.Location = new Point(10, 10);
            // Set the text of button2 to "Cancel".
            button2.Text = "Cancel";
            // Set the position of the button based on the location of button1.
            button2.Location
               = new Point(button1.Left, button1.Height + button1.Top + 10);
            // Make button1's dialog result OK.
            button1.DialogResult = DialogResult.OK;
            // Make button2's dialog result Cancel.
            button2.DialogResult = DialogResult.Cancel;
            // Set the caption bar text of the form.   
            Form2.Text = "My Dialog Box";

            // Define the border style of the form to a dialog box.
            Form2.FormBorderStyle = FormBorderStyle.FixedDialog;
            // Set the accept button of the form to button1.
            Form2.AcceptButton = button1;
            // Set the cancel button of the form to button2.
            Form2.CancelButton = button2;
            // Set the start position of the form to the center of the screen.
            Form2.StartPosition = FormStartPosition.CenterScreen;

            // Add button1 to the form.
            Form2.Controls.Add(button1);
            // Add button2 to the form.
            Form2.Controls.Add(button2);

            // Display the form as a modal dialog box.
            Form2.ShowDialog();

            // Determine if the OK button was clicked on the dialog box.
            if (Form2.DialogResult == DialogResult.OK)
            {
                // Display a message box indicating that the OK button was clicked.
                MessageBox.Show("The OK button on the form was clicked.","",MessageBoxButtons.OK,MessageBoxIcon.Error);
                // Optional: Call the Dispose method when you are finished with the dialog box.
                Form2.Dispose();
            }
            else
            {
                // Display a message box indicating that the Cancel button was clicked.
                MessageBox.Show("The Cancel button on the form was clicked.");
                // Optional: Call the Dispose method when you are finished with the dialog box.
                Form2.Dispose();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            bckIniciarComponetes = new BackgroundWorker();
            bckIniciarComponetes.DoWork += new System.ComponentModel.DoWorkEventHandler(this.bckIniciarComponetes_DoWork);
            bckIniciarComponetes.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.bckIniciarComponetes_RunWorkerCompleted);
            bckIniciarComponetes.RunWorkerAsync();
        }

        private void bckIniciarComponetes_DoWork(object sender, DoWorkEventArgs e) 
        {

        }

        private void bckIniciarComponetes_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {

        }

        public DialogResult CallMessageBox(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
        {
            return MessageBox.Show(text, caption, buttons, icon);
        }

    }

}
